package pers.hl.module_main.explore

import com.blankj.utilcode.util.GsonUtils
import com.chad.library.adapter.base.entity.MultiItemEntity
import pers.hl.common.utils.AssetUtils
import pers.hl.lib_global.KTApplication
import pers.hl.lib_global.model.bean.Book
import pers.hl.lib_global.model.bean.BookTag
import pers.hl.lib_global.model.bean.Library

abstract class ExploreLayoutBean(override val itemType: Int) : MultiItemEntity {

    companion object {
        const val TYPE_LIBRARY = 1
        const val TYPE_BANNER = 2
        const val TYPE_CATEGORY = 3
        const val TYPE_RV_TITLE = 4
        const val TYPE_RV_CONTENT_BOOK = 5
    }

    abstract fun getData() : Any?

    class LibraryBean: ExploreLayoutBean(TYPE_LIBRARY) {
        override fun getData(): Library {
            val json = AssetUtils.getJson(KTApplication.getInstance(), "library.json")
            return GsonUtils.fromJson(json, Library::class.java)
        }
    }

    class BannerBean(private val data: List<Book>): ExploreLayoutBean(TYPE_BANNER) {
        override fun getData(): List<Book> {
            return data
        }
    }

    class CategoryBean: ExploreLayoutBean(TYPE_CATEGORY) {
        override fun getData(): Book {
            val json = AssetUtils.getJson(KTApplication.getInstance(), "book.json")
            return GsonUtils.fromJson(json, Book::class.java)
        }
    }

    class RvTitleBean(private val tag: BookTag?): ExploreLayoutBean(TYPE_RV_TITLE) {
        override fun getData(): BookTag? {
            return tag
        }
    }

    class RvBookContentBean(private val books: List<Book>?): ExploreLayoutBean(TYPE_RV_CONTENT_BOOK) {
        override fun getData(): List<Book>? {
            return books
        }
    }

}